package cn.remex.core.util;

import cn.remex.core.exception.NestedException;
import cn.remex.core.exception.ServiceCode;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Formatter;
import java.util.Locale;

/**
 * 名称：
 * 缩写：
 * 用途：
 * Created by yangy on 2016/12/24 0024.
 */
public class SystemHelper {
	public static String getLocalIP(){
		try{
			InetAddress address = InetAddress.getLocalHost();
			NetworkInterface ni = NetworkInterface.getByInetAddress(address);
			//ni.getInetAddresses().nextElement().getAddress();
			return address.getHostAddress();
//			byte[] mac = ni.getHardwareAddress();
//			String sMAC = "";
//			Formatter formatter = new Formatter();
//			for (int i = 0; i < mac.length; i++) {
//				sMAC = formatter.format(Locale.getDefault(), "%02X%s", mac[i],
//						(i < mac.length - 1) ? "-" : "").toString();
//
//			}
		}catch(Exception e){
			throw new NestedException(ServiceCode.FAIL, "获取本机服务器IP&MAC异常");
		}
	}
}
